package com.sakura.util.synchronizedTest;/**
 * Created by apple on 2019/8/21.
 */

/**
 * @author jixd
 * @Description
 * @Date 2019/8/21 5:11 PM
 * @Version 1.0
 **/
public class Test {
    public synchronized void testSynchronized(){
            System.out.println("开始"+this.hashCode());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("结束"+this.hashCode());

    }

    public static void main(String[] args) {

        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                Test test = new Test();
                test.testSynchronized();
            }
        });
        thread.start();
        Thread thread2 = new Thread(new Runnable() {
            @Override
            public void run() {
                Test test = new Test();
                test.testSynchronized();
            }
        });
        thread2.start();
    }
}
